<template>
  <div>
    <div v-if="!merBusinessConfigList">
      <Error></Error>
    </div>
    <div v-if="merBusinessConfigList">
      <div class="inquireDiv">
        <el-row>
          <el-col :span="5">
            <label>商户号：
              <el-input v-model="form.merchantName" placeholder="请输入商户号"></el-input>
            </label>
          </el-col>
          <el-col :span="5">
            <label>业务类型：
              <el-select v-model="form.merchantBusiness" placeholder="请选择业务类型">
                <el-option v-for="(item,key,index) in business" :label="item" :value="key" :key="index"></el-option>
              </el-select>
            </label>
          </el-col>
          <el-col :span="5">
            <label>金融类型：
              <el-select v-model="form.moneyType" placeholder="请选择金融类型">
                <el-option v-for="(item,key,index) in moneyType" :label="item" :value="key" :key="index"></el-option>
              </el-select>
            </label>
          </el-col>
          <el-col :span="5">
            <label>状态：
              <el-select v-model="form.merchantState" placeholder="请选择状态">
                <el-option label="全部" value=""></el-option>
                <el-option label="正常" value="1"></el-option>
                <el-option label="禁用" value="2"></el-option>
              </el-select>
            </label>
          </el-col>
          <el-col :span="4" style="text-align: right">
            <el-button type="primary" @click="examineFn">查 询</el-button>
          </el-col>
        </el-row>
      </div>
      <div class="tableDiv" v-loading="loading">
        <el-row>
          <el-table
            :cell-class-name="addClass"
            :data="tableData"
            stripe
            border
            style="width: 100%">
            <el-table-column
              type="index"
              label="#"
              align="center"
              width="48"
              >
            </el-table-column>
            <el-table-column
              prop="mer_no"
              label="商户号"
              align="center"
              width="128"
              >
            </el-table-column>
            <el-table-column
              prop="mer_name"
              label="商户名称"
              align="center"
              width="80"
              >
            </el-table-column>
            <el-table-column
              prop="mbc_bank_name"
              label="申请银行"
              align="center"
              width="150"
              >
            </el-table-column>
            <el-table-column
              prop="mbc_money"
              label="设置金额"
              align="center"
              width="100"
              >
            </el-table-column>
            <el-table-column
              label="金融类型"
              align="center"
              width="80"
              >
              <template slot-scope="scope">
                <span style="color:#F56C6C" v-if="scope.row.mbc_money_type_text == '收费'">收费</span>
                <span style="color:#409EFF" v-else>{{scope.row.mbc_money_type_text}}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="mbc_business_text"
              label="业务类型"
              align="center"
              width="80"
              >
            </el-table-column>
            <el-table-column
              label="状态"
              align="center"
              width="60"
              >
              <template slot-scope="scope">
                <span style="color:#F56C6C" v-if="scope.row.mbc_status !== '1'">禁用</span>
                <span style="color:#409EFF" v-if="scope.row.mbc_status == '1'">正常</span>
              </template>
                   
            </el-table-column>
            <el-table-column
              prop="mbc_create_time"
              sortable
              label="创建时间"
              align="left"
            >
            </el-table-column>
            <!--<el-table-column-->
              <!--align="center">-->
              <!--<template slot="header" slot-scope="scope">-->
                <!--<div class="el-table-header">-->
                  <!--<el-button type="primary" @click.native.prevent="addInformation" style="visibility: hidden">添加-->
                  <!--</el-button>-->
                <!--</div>-->
              <!--</template>-->
              <!--&lt;!&ndash;<template slot-scope="scope">&ndash;&gt;-->
                <!--&lt;!&ndash;<el-button v-show="scope.row.mbc_status == '1'"&ndash;&gt;-->
                           <!--&lt;!&ndash;v-if="updateConfig"&ndash;&gt;-->
                           <!--&lt;!&ndash;@click.native.prevent="deleteRow(scope.$index,tableData,2)"&ndash;&gt;-->
                           <!--&lt;!&ndash;type="danger"&ndash;&gt;-->
                           <!--&lt;!&ndash;size="small">&ndash;&gt;-->
                  <!--&lt;!&ndash;禁用&ndash;&gt;-->
                <!--&lt;!&ndash;</el-button>&ndash;&gt;-->
                <!--&lt;!&ndash;<el-button v-show="scope.row.mbc_status !== '1'"&ndash;&gt;-->
                           <!--&lt;!&ndash;v-if="updateConfig"&ndash;&gt;-->
                           <!--&lt;!&ndash;@click.native.prevent="deleteRow(scope.$index,tableData,1)"&ndash;&gt;-->
                           <!--&lt;!&ndash;type="success"&ndash;&gt;-->
                           <!--&lt;!&ndash;size="small">&ndash;&gt;-->
                  <!--&lt;!&ndash;启用&ndash;&gt;-->
                <!--&lt;!&ndash;</el-button>&ndash;&gt;-->
              <!--&lt;!&ndash;</template>&ndash;&gt;-->
            <!--</el-table-column>-->
          </el-table>
          <el-col :span="24">
            <div class="block" v-if="total">
              <el-pagination
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-size="10"
                layout="total, prev, pager, next"
                :total="total">
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
  import Error from '../errorPage/errorPage401'
  export default {
    data() {
      return {
        mid: '',
        loading: true,
        currentPage: '',
        form: {
          merchantName: '',
          merchantState: '',
          merchantBusiness: '',
          moneyType: '',
        },
        tableData: [],
        total: '',
        updateConfig: false,
        moneyType: {},
        business: {},
        merBusinessConfigList:false
      }
    },
    methods: {
      //初始化
      initFn: function (page) {
        let data = {
          page: page,
          mer_no: this.form.merchantName,
          status: this.form.merchantState,
          business: this.form.merchantBusiness,
          money_type: this.form.moneyType
        };
        let str = this.encryptionAesRsa(data);
        let encryptData = str.split('%$#@zjt@#$%')[0];
        let encryptKey = str.split('%$#@zjt@#$%')[1];
        let incomData = {
          map: 'admin_merchant_config_list',
          plum_session_api: localStorage.getItem('token'),
          encryptData: encryptKey,
          encryptKey: encryptData
        };
        this.$http.post('', incomData).then((data) => {
          if (data.ec == 200) {
            this.loading = false;
            this.total = Number(data.data.count);
            this.currentPage = Number(data.data.page);
            this.tableData = data.data.list;
            this.business = data.data.business;
            this.moneyType = data.data.money_type;
          } else if (data.ec == 401) {
            this.$message.error(data.em);
            setTimeout(() => {
              this.exitLogin();
            }, 1500)
          } else {
            this.$message.error(data.em);
          }
        }).catch((err) => {
          this.$message.error('error!');
        })
      },
      //查询
      examineFn: function () {
        this.initFn(1)
      },
      //列变色
      addClass({row, column, rowIndex, columnIndex}) {
        if (columnIndex === 4) {
          return 'cell-blue'
        }
      },
      //点击分页
      handleCurrentChange(val) {
        this.$router.replace({
          path: this.$route.path,
          query: {
            page: val,
          }
        });
        this.loading = true;
        this.initFn(val);
      },
      // 禁用/启用按钮
      deleteRow(index, row, status) {
        let str = '';
        if (status == 1) {
          str = '此操作将启用该用户, 是否继续?'
        } else {
          str = '此操作将禁用该用户, 是否继续?'
        }
        this.$confirm(str, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.mid = row[index].mbc_id;
          let data = {
            mbc_id: this.mid,
            status: status
          };
          let str = this.encryptionAesRsa(data);
          let encryptData = str.split('%$#@zjt@#$%')[0];
          let encryptKey = str.split('%$#@zjt@#$%')[1];
          let incomData = {
            map: 'admin_mer_config_status',
            plum_session_api: localStorage.getItem('token'),
            encryptData: encryptKey,
            encryptKey: encryptData
          };
          this.$http.post('', incomData).then((data) => {
            if (data.ec == 200) {
              this.$message.success(data.em);
              this.initFn(this.currentPage)
            } else if (data.ec == 401) {
              this.$message.error(data.em);
              setTimeout(() => {
                this.exitLogin();
              }, 1500)
            } else {
              this.$message.error(data.em);
            }
          }).catch((err) => {
            this.$message.error('error!');
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作'
          });
        });
      },
    },
    // created() {
    //   this.currentPage = this.$route.query.page ? this.$route.query.page : 1;
    //   this.initFn(this.currentPage);
    // },
    mounted() {

        this.currentPage = this.$route.query.page ? this.$route.query.page : 1;
        let merNo = this.$route.params.merNo;
        let mbBusiness = this.$route.params.mbBusiness;
        merNo = (merNo == null || merNo == "" || typeof (merNo) == "undefined") ? "" : merNo;
        mbBusiness = (mbBusiness == null || mbBusiness == "" || typeof (mbBusiness) == "undefined") ? "" : mbBusiness;
        this.form.merchantName = merNo;
        this.form.merchantBusiness = mbBusiness;
        this.initFn(this.currentPage);
      // 按钮权限
      let buttonMenu = localStorage.getItem('buttonMenu');
      buttonMenu = this.edecryptButton(buttonMenu);
      if (buttonMenu.indexOf('updateConfig') !== -1) {
        this.updateConfig = true
      }
      //页面权限
      if (buttonMenu.indexOf('merBusinessConfigList') !== -1 && buttonMenu.indexOf('merBusinessConfigOne') !== -1) {
        this.merBusinessConfigList = true
      }
    },
    components:{
      Error
    }
  }
</script>

<style scoped>
  .inquireDiv {
    padding: 30px;
    background: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)
  }

  .inquireDiv label {
    display: inline-block;
  }

  .inquireDiv .el-input {
    width: 220px;
  }

  .tableDiv {
    margin-top: 20px;
  }

  .el-col {
    border-radius: 4px;
    height: 75px;
    background-color: #fff;
  }

  .tableDiv >>> .el-pagination {
    height: 30px;
    line-height: 30px;
    margin-top: 25px;
    text-align: center;
  }

  .tableDiv >>> .cell-blue {
    color: #F56C6C !important;
  }

  .drawerDiv {
    width: 100%;
    height: calc(90vh);
    padding: 20px;
    overflow-y: auto;
    box-sizing: border-box;
  }

  .drawerDiv h2 {
    text-align: center;
    font-size: 20px;
    margin: 20px 0;
  }

  .drawerDiv p {
    font-size: 16px;
    color: #000000;
    margin-top: 10px;
  }

  .drawerDiv p label {
    font-size: 16px;
    vertical-align: middle;
    font-weight: 600;
    display: inline-block;
    width: 80px;
    text-align: right;
  }

  .drawerDiv p span {
    font-size: 14px;
    vertical-align: middle;
    color: #555555;
    margin-left: 5px;
  }

  .dialogFormVisibleDiv >>> .el-dialog {
    width: 800px;
  }

  .dialogFormVisibleDiv .el-input {
    width: 550px;
  }

  .el-table-header >>> .el-button {
    float: right;
    height: 40px;
  }
</style>
